function reallocExternType(p,n)
  use derived,only:ExternalEvent
  implicit none

  type(ExternalEvent),pointer,dimension(:) :: reallocExternType,p
  integer,intent(in) :: n
  integer :: i,j,nold,ierr

  allocate(reallocExternType(1:n),stat=ierr)
  if (ierr.ne.0) call abnormal_stop("reallocExternType",&
       "Memory allocation cause an error.")

  do i=1,n
     reallocExternType(i)%flux=0
     reallocExternType(i)%dose=0
     reallocExternType(i)%rand=0
     reallocExternType(i)%dise=0
     reallocExternType(i)%filename=""
     reallocExternType(i)%cas_filename=""
     reallocExternType(i)%dpa_filename=""
     reallocExternType(i)%n_occur=0
     reallocExternType(i)%dpa=0.0
     reallocExternType(i)%sdpa=0.0
     reallocExternType(i)%n_objset=0.0
     nullify(reallocExternType(i)%cgrid)
     nullify(reallocExternType(i)%cprob)
     nullify(reallocExternType(i)%cascade_list)
     nullify(reallocExternType(i)%dgrid)
     nullify(reallocExternType(i)%dprob)
     nullify(reallocExternType(i)%objset)
     nullify(reallocExternType(i)%count_cascade)
     nullify(reallocExternType(i)%count_dpa)

     reallocExternType(i)%dist(1)=0
     reallocExternType(i)%dist(2)=0
     reallocExternType(i)%n_type=0
     nullify(reallocExternType(i)%source_name)
     nullify(reallocExternType(i)%source_type)
  end do

  if (.not.associated(p)) return

  nold=n-1
  do i=1,nold
     reallocExternType(i)%event_type=p(i)%event_type
     reallocExternType(i)%flux=p(i)%flux
     reallocExternType(i)%dose=p(i)%dose
     reallocExternType(i)%dise=p(i)%dise
     if (p(i)%event_type.eq.1) then
        reallocExternType(i)%rand=p(i)%rand
        reallocExternType(i)%filename=p(i)%filename
        reallocExternType(i)%dpa_filename=p(i)%dpa_filename
        reallocExternType(i)%cas_filename=p(i)%cas_filename
     else if (p(i)%event_type.eq.3) then
        reallocExternType(i)%dist(1)=p(i)%dist(1)
        reallocExternType(i)%dist(2)=p(i)%dist(2)
        reallocExternType(i)%n_type=p(i)%n_type
        reallocExternType(i)%dpa_filename=&
             p(i)%dpa_filename
        allocate(reallocExternType(i)%source_name(p(i)%n_type))
        do j=1,p(i)%n_type
           reallocExternType(i)%source_name(j)=&
                p(i)%source_name(j)
        end do
        deallocate(p(i)%source_name)
     else
        ! event_type=2 : Not realized yet.
     end if
  end do

  deallocate(p)

  return
 
end function reallocExternType
